<template>
  <div class="app-container">
    <div id="printBox">
      <div
        style="margin-bottom: 20px"
        v-for="item in matterData"
        :key="item.id"
      >
        <el-descriptions :column="2" border>
          <el-descriptions-item label="物料名称">{{
            item.name
          }}</el-descriptions-item>
          <el-descriptions-item label="物料编号">{{
            item.no
          }}</el-descriptions-item>
          <el-descriptions-item label="CAS号">{{
            item.casNo
          }}</el-descriptions-item>
          <el-descriptions-item label="物料类型"
            >{{ item.type }}
          </el-descriptions-item>
          <el-descriptions-item label="批次号">{{
            item.batchNo
          }}</el-descriptions-item>
          <el-descriptions-item label="所属企业">{{
            item.applyUnit
          }}</el-descriptions-item>
        </el-descriptions>
        <div class="demo-drawer__footer" style="margin-top: 10px">
          <div style="text-align: center" v-show="matterData.length > 0">
            <el-button size="small" @click="printFun(item)">打印条码</el-button>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script setup lang="ts">
import request from "@/utils/request";
import { getLodop } from "@/utils/LodopFuncs";
const matterData = [
  {
    id: "6922266462849",
    name: "fsdfsd",
    no: "01",
    casNo: "33",
    type: "333",
    batchNo: "333",
    applyUnit: "333",
  },
];
function printFun(pitem) {
  console.log("打印条码", pitem);
  let LODOP = getLodop();
  LODOP.PRINT_INIT(pitem.name);
  //LODOP.SET_PRINT_PAGESIZE(1, 300, 200, "");
  LODOP.ADD_PRINT_RECT(0, 5, 285, 190, 0, 1); //上左宽高  0实线 1虚线， 线条
  LODOP.SET_PRINT_STYLE("FontSize", 7.5);
  let y = 10;
  let yy = y;
  LODOP.ADD_PRINT_TEXT(y, 15, 300, 15, "物料名称：" + pitem.name);
  y = yy + 20;
  LODOP.ADD_PRINT_TEXT(y, 15, 140, 15, "CAS号：" + pitem.casNo);
  LODOP.ADD_PRINT_TEXT(y, 155, 140, 15, "物料类型：" + pitem.type);
  y += 20;
  LODOP.ADD_PRINT_TEXT(y, 15, 140, 15, "批次号：" + pitem.batchNo);
  LODOP.ADD_PRINT_TEXT(y, 155, 150, 15, "物料编号：" + pitem.no);

  if (y < 110) {
    y += 40;
  } else {
    y += 20;
  }
  LODOP.ADD_PRINT_BARCODE(y, 50, 200, 60, "128Auto", pitem.id);
  LODOP.NEWPAGE();
  y = 10;
  yy = y;
  LODOP.ADD_PRINT_TEXT(y, 15, 300, 15, "物料名称：" + pitem.name);
  y = yy + 20;
  LODOP.ADD_PRINT_TEXT(y, 15, 140, 15, "CAS号：" + pitem.casNo);
  LODOP.ADD_PRINT_TEXT(y, 155, 140, 15, "物料类型：" + pitem.type);
  y += 20;
  LODOP.ADD_PRINT_TEXT(y, 15, 140, 15, "批次号：" + pitem.batchNo);
  LODOP.ADD_PRINT_TEXT(y, 155, 150, 15, "物料编号：" + pitem.no);

  if (y < 110) {
    y += 40;
  } else {
    y += 20;
  }
  LODOP.ADD_PRINT_BARCODE(y, 50, 200, 60, "128Auto", pitem.id);

  LODOP.PREVIEW(); //预览
  //LODOP.PRINT(); //直接打印
}
</script>
